#!/bin/bash -e

function info() {
echo Usage: `basename $0` 'list'
exit 1
}

while getopts  ":p:f:" opt; do
	case  $opt  in
		p) out_prefix=$OPTARG;;
		f) suffix=$OPTARG;;
		*) info;;
	esac
done
shift $(($OPTIND - 1))


if [ $# -lt 1 ]; then info; fi

. $var


list=$1

# bed=/mnt/ilustre/app/medical/data/adm/1.bed
bed1=/mnt/ilustre/app/medical/data/adm/interval.bed
bed=/mnt/ilustre/users/fei.yang/data/intervals/1/b37.1_22.bed
header=/mnt/ilustre/app/medical/data/adm/sam_header

IFS=$'\n'
for i in `cat $list`; do

    # nam=`basename $i|cut -f1 -d.`
    # nam=`echo $i|cut -f2 -d.`
    nam=`echo $i|cut -f1`
    bam=`echo $i|cut -f2`
    echo $nam
    base=$out_prefix.$nam
    # samtools view -@4 -f3 -F12 -L $bed $bam > $base.sam
    
    # cat $header $out_prefix.$nam.sam > $out_prefix.$nam.sam.1
    # mv $out_prefix.$nam.sam.1 $out_prefix.$nam.sam
    
    # sort_idx_sam.sh -p$out_prefix.$nam $out_prefix.$nam.sam
    
    # rg_add_replace.sh -s$nam -p$out_prefix.$nam $out_prefix.$nam.sort.bam
    
    samtools bam2fq -n $bam > $base.fq
    aln180309.sh -s$nam -p$out_prefix.$nam -b$bed $base.fq
    deldup.sh -m -p$base $base.sort.bam
    
    recal0630.sh -l $bed -p$base $base.markdup.bam
    hap.sh -p$base $base.realn.recal.bam $bed1
    
    # rm $out_prefix.$nam.sort.bam* $out_prefix.$nam.sam

done

. $cmd_done